// DirectiveParser.cpp : Implementation of CDirectiveParser

#include "stdafx.h"
#include "DirectiveParser.h"
#include ".\directiveparser.h"


// CDirectiveParser


STDMETHODIMP CDirectiveParser::Parse(BSTR bstrText, IDirectiveCallback* callback)
{
	if (callback == NULL)
		return E_POINTER;
	COLE2T pszText(bstrText);
	
	directiveparser parser;
	
	HRESULT hr = E_FAIL;
	if (parser.parsedirective(pszText))
	{
		CComBSTR bstrName(parser.directivename.c_str());
		callback->SetName(bstrName);
		for(map<string, string>::iterator iter = parser.attributes.begin();
			iter != parser.attributes.end(); iter++)
		{
			CComBSTR bstrName  = iter->first.c_str();
			CComBSTR bstrValue = iter->second.c_str();
			callback->AddAttribute(bstrName, bstrValue);
		}
		hr = S_OK;
	}
	else
	{
		Error("Directive Parsing Failed.");
#ifdef DEBUG
		cout << "Directive Parsing Failed!!!" << endl;
#endif
		hr = E_FAIL;
	}

	return hr;
}
